package at.fhhagenberg.se.tjr.protocol;

import com.sentilla.platform.tmote.Dispatcher;
import com.sentilla.platform.tmote.Protocol;
import com.sentilla.platform.tmote.Receiver;
import com.sentilla.platform.tmote.Sender;
import com.sentilla.system.Drivers;

public class RegisterProtocol extends Protocol {

	public boolean doesInstanceMatch(Object obj) {
		return (obj instanceof TrafficJamMessage) ? true : false;
	}

	public Receiver newReceiver() {
		return new RegisterReceiver();
	}

	public Sender newSender() {
		return new RegisterSender();
	}

	public void stackReceive(Receiver prevRcvr) {
		Dispatcher ds = Drivers.getDriver("disp", Dispatcher.class); 
		RegisterReceiver rcvr = new RegisterReceiver(); 
		rcvr.data = prevRcvr.data; 
		rcvr.addMetadata(prevRcvr); 
		ds.dispatch(rcvr);
	}

	public void stackSend(Sender s) {
		Dispatcher ds = Drivers.getDriver("disp", Dispatcher.class); 
		RegisterSender sender = new RegisterSender();
		sender.data = s.data;
		ds.queueForSend(sender);
	}

	public String getDriverName(int n) {
		return "RegisterDriver";
	}

}
